package com.zd.miko.tally.MVP.ModuleTallyList

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.zd.miko.tally.R
import com.zd.miko.tally.Utils.ActivityUtils
import com.zd.miko.tally.Utils.Utils
import kotlinx.android.synthetic.main.activity_tally_list.*

class TallyListActivity : AppCompatActivity() {

    lateinit var presenter: TallyListContract.Presenter

    val EXPEND = 0
    val INCOME = 1
    var type = EXPEND

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tally_list)
        initToolbar()
        initFragment()
        initEvent()
    }

    private fun initEvent() {
        ln_tallyType.setOnClickListener {
            if(type == EXPEND){
                type = INCOME
            }else{
                type = EXPEND
            }
        }
    }
    private fun changeType(){

    }


    private fun initFragment() {
        var listFragment: TallyListFragment? = supportFragmentManager
                .findFragmentById(R.id.id_contentFrame) as TallyListFragment?
        if (listFragment == null) {
            listFragment = TallyListFragment()
            ActivityUtils.addFragmentToRoot(supportFragmentManager,
                    listFragment, R.id.id_contentFrame, null)
        }

        presenter = TallyListPresenter(listFragment, this)
    }

    private fun initToolbar() {

        rlToolbar.setBackgroundColor(this.resources.getColor(R.color.editToolbar))

        val params1 = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT)
        params1.setMargins(0, Utils.getStatusBarHeight(), 0, 0)

        toolbarContainer.layoutParams = params1

        setSupportActionBar(toolbar)
        supportActionBar!!.setDisplayShowTitleEnabled(false)
        supportActionBar!!.setDisplayHomeAsUpEnabled(true)
    }
}
